//
//  HJChatFriendModel.m
//  KaiChat
//
//  Created by lx on 2023/10/20.
//

#import "HJChatFriendModel.h"
#import "HJChatUserModel.h"

@implementation HJChatFriendModel

MJLogAllIvars


+ (NSArray *)bg_uniqueKeys {
    return @[@"userId"];
}

+ (NSArray *)bg_ignoreKeys {
    return @[@"showName", @"isSelect"];
}
 
- (NSString *)bg_tableName {
    return [NSString stringWithFormat:@"%@_%@", NSStringFromClass(self.class), HJUserInfo.userId];
}

+ (NSString *)bg_tableName {
    return [NSString stringWithFormat:@"%@_%@", NSStringFromClass(self.class), HJUserInfo.userId];
}


+ (HJChatFriendModel *)modelWithDict:(NSDictionary *)dict {
        
    HJChatFriendModel *model = [[HJChatFriendModel alloc] init];
    model.avatar = dict[@"profile_picture"];
    model.nickname = dict[@"nickname"];
    model.remarks = dict[@"friend_remarks"];
    if ([dict.allKeys containsObject:@"friend_user_id"]) {
        model.userId = toString(dict[@"friend_user_id"]);
    } else {
        model.userId = toString(dict[@"id"]);
    }
    model.sessionId = toString(dict[@"im_session_id"]);
    model.brief = dict[@"brief"];
    model.uid = dict[@"no"];
    return model;
}

//查询用户信息的时候可以更新好友信息这个表
+ (HJChatFriendModel *)modelWithUserModel:(HJChatUserModel *)userModel {
    HJChatFriendModel *model = [[HJChatFriendModel alloc] init];
    model.userId = userModel.userId;
    model.avatar = userModel.avatar;
    model.nickname = userModel.nickname;
    model.sessionId = toString(userModel.sessionId);
    model.brief = userModel.brief;
    model.uid = userModel.uid;
    return model;
}

- (NSString *)showName {
//    if (!isEmptyString(self.remarks)) {
//        return self.remarks;
//    }
    if (!isEmptyString(self.nickname)) {
        return self.nickname;
    }
    if (!isEmptyString(self.uid)) {
        return self.uid;
    }
    return toString(self.userId);
}

@end

